Skip to content

[2.0.0] Fix issue with init I2C for esp32 S2 #4776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 175 commits into from
Mar 31, 2021
Merged

[2.0.0] Fix issue with init I2C for esp32 S2 #4776

merged 175 commits into from
Mar 31, 2021

Conversation

chegewara
Copy link
Contributor

No description provided.

@chegewara
Copy link
Contributor Author

chegewara commented Feb 8, 2021

Actually without this fix I2C crash even with arduino IDE and most recent idf-release/v4.2.
@me-no-dev

19:43:27.250 -> E (162) i2c: i2c_param_config(644): i2c clock choice is invalid, please check flag and frequency
19:43:27.250 -> [   654][E][esp32-hal-i2c.c:1828] i2cInit(): i2c_param_config failed
19:43:27.250 -> Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

@makermelissa
Copy link
Contributor

You could probably fix it by adding:

conf.clk_flags = 0;

I found the answer at espressif/esp-idf#6293 (comment) and tested it out successfully.

@chegewara
Copy link
Contributor Author

You could probably fix it by adding:

conf.clk_flags = 0;

I found the answer at espressif/esp-idf#6293 (comment) and tested it out successfully.

Thats true, but next time when esp-idf will be updated with new parameter you will have to update this library, and again and again. This way of init variable is good practice:
i2c_config_t conf = {0};

@makermelissa
Copy link
Contributor

Ah, I get what you're saying. :)

Copy link
Contributor

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and this fix worked for me.

@me-no-dev
Copy link
Member

I would say, use memset to set the whole struct to zero, not just the first element :)

i2c_config_t conf;
memset(conf, 0, sizeof(i2c_config_t)); //Might require to #include "string.h"

@chegewara
Copy link
Contributor Author

Well, i always thought it is the way to initialize all elements in struct with 0.

@me-no-dev
Copy link
Member

https://stackoverflow.com/questions/6891720/initialize-reset-struct-to-zero-null/6891731#comment46703800_6891773

The answer below that comment also gives some info. And given that this has caused issues on ESP32 before, I suggest you change it to memset :)

@me-no-dev me-no-dev changed the title Fix issue with init I2C in arduino as component [2.0.0] Fix issue with init I2C in arduino as component Feb 16, 2021
@chegewara chegewara changed the title [2.0.0] Fix issue with init I2C in arduino as component [2.0.0] Fix issue with init I2C for esp32 S2 Feb 20, 2021
@VojtechBartoska VojtechBartoska added this to the 2.0.0 milestone Mar 2, 2021
LFSaw added a commit to LFSaw/AC101 that referenced this pull request Mar 27, 2021
as proposed in espressif/arduino-esp32#4776. Fixes `i2c_param_config` Errors with `esp-idf > 2020r3-8.4.0`
@me-no-dev me-no-dev changed the base branch from idf-release/v4.2 to v2-s2 March 31, 2021 22:02
@me-no-dev me-no-dev merged commit baaf9f2 into espressif:v2-s2 Mar 31, 2021
@ncohen17
Copy link

ncohen17 commented Jun 7, 2022

Hi,

I am having a similar issue. I am trying to run the ESP-NOW protocol together with the I2C interface but I am getting an error.

I am using the M5Stack ATOM, which uses the ESP32-PICO chip.

This is what I am getting on the serial terminal.

E (39) i2c: i2c_param_config(671): i2c clock choice is invalid, please check flag and frequency I2C slave init failed

I have tried adding this conf.clk_flags= 0; and this i2c_config_t conf; memset(conf, 0, sizeof(i2c_config_t)); to the header file but it is still not working. I am getting the same error message on ther serial terminal.

Can someone please advise on the fix to this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.